import Vue from "vue";
import Vuex from "vuex";
import envEnum from "./envEnum";
import envConfig from "./env";
// #ifdef H5
import createPersistedState from 'vuex-persistedstate'
// #endif

Vue.use(Vuex);
let env = envConfig.env;

let defaultState = {
        hasLogin: false,
        user:{},
        pin:'',
        token: "",
        shopList:[],
        shop:{},
        allWorkList:[],
        myWorkList:[],
        platform:"android",
        deviceId:"",
        clientId:"",
        vuex_env: env
    };
// #ifdef H5
const vuexPersisted = new createPersistedState({
    storage: {
        getItem: key => {
            return uni.getStorageSync(key)
        },
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: key => uni.removeStorageSync(key)
    }
});
// #endif

const store = new Vuex.Store({
    // #ifdef H5
    plugins:[vuexPersisted],
    // #endif
    state:JSON.parse(JSON.stringify(defaultState)),
    mutations: {
    },
    actions:{
    },
    getters: {
        vuex_env_conf: state => envEnum[String(state.vuex_env)]
    }
});

export default store;
